package com.sleepfish.generator.domain;

/**
 * @author fumingchao
 * @Description: 表字段修改记录表
 * @date 2022/2/22 15:29
 */
public class TableColumnTran{

    public static String HEAD="ALTER TABLE ";

    private Long columnId;

    private String operation;
    private String tableName;
    private String columnComment;
    private String columnName;
    private String oldColumnName;
    private String columnType;
    private Long len;
    private Long tableId;

    public Long getColumnId() {
        return columnId;
    }

    public void setColumnId(Long columnId) {
        this.columnId = columnId;
    }

    public String getOldColumnName() {
        return oldColumnName;
    }

    public void setOldColumnName(String oldColumnName) {
        this.oldColumnName = oldColumnName;
    }

    public Long getTableId() {
        return tableId;
    }

    public void setTableId(Long tableId) {
        this.tableId = tableId;
    }

    public String getOperation() {
        return operation;
    }

    public void setOperation(String operation) {
        this.operation = operation;
    }

    public String getTableName() {
        return tableName;
    }

    public void setTableName(String tableName) {
        this.tableName = tableName;
    }

    public String getColumnComment() {
        return columnComment;
    }

    public void setColumnComment(String columnComment) {
        this.columnComment = columnComment;
    }

    public String getColumnName() {
        return columnName;
    }

    public void setColumnName(String columnName) {
        this.columnName = columnName;
    }

    public String getColumnType() {
        return columnType;
    }

    public void setColumnType(String columnType) {
        this.columnType = columnType;
    }

    public Long getLen() {
        return len;
    }

    public void setLen(Long len) {
        this.len = len;
    }

    //ALTER TABLE api_directory ADD test  VARCHAR(100) comment '评论'
    public String addSql() {
        String str;
        if(columnType.equals("text")){
           str = HEAD+
                tableName+" "+
                operation+" "+
                columnName+" "+
                columnType+" comment '"+
                columnComment+"'";
        }else {
            str=HEAD+
                tableName+" "+
                operation+" "+
                columnName+" "+
                columnType+"("+len+") comment '"+
                columnComment+"'";
        }
        return str;

    }
    //alter  table table1 change column2 column1 decimal(10,1) DEFAULT NULL COMMENT '注释'
    public String updateSql() {
        return HEAD+
                tableName+" "+
                operation+" "+
                oldColumnName+" "+
                columnName+" "+
                columnType+"("+len+") comment '"+
                columnComment+"'";

    }

    //alter table student DROP COLUMN age;

    public String deleteSql() {
        return HEAD+
                tableName+" "+
                operation+" "+
                " COLUMN "+
                columnName;

    }
}
